package com.wu.minstack;

import java.util.Stack;

/**
 * 包含min函数的最小栈
 * @author lynn
 * @date 2020/8/2 - 11:19
 */
public class Solution {

    Stack<Integer> stack = new Stack<Integer>();
    Stack<Integer> minStack = new Stack<Integer>();
    public void push(int node) {
        stack.push(node);
        if (minStack.empty()){
            minStack.push(node);
        }else {
            if (minStack.peek() > node){
                minStack.push(node);
            }else {
                minStack.push(minStack.peek());
            }
        }

    }

    public void pop() {
        stack.pop();
        minStack.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}